*************************************************************************************
*****			Please cite Georgiadou et al. (2018) as indicated in 			*****
*****  	https://www.sciencedirect.com/science/article/pii/S026137941830026X		*****
*************************************************************************************


use Data/GRR_data.dta, clear

***** Figure 1
keep nuts_2 nuts2 year er_average prr_average // keep only variables used in R for maps
saveold Data/GRR_dataMapsR.dta, version(12) replace




use Data/GRR_data.dta, clear
***** Figure 2
*** Interpolation to obtain votes for non-electoral years. 
*** radical_right=PRR, ext_right_cat1=ER, far_right=FR
sort nuts_2 year
ipolate radical_right_votes year, gen(radicalright_votes_ipol) epolate by(nuts_2) // ipolate votes to fill in non-elections years
ipolate ext_right_cat1_votes year, gen(extright_cat1_votes_ipol) epolate by(nuts_2) // ipolate votes to fill in non-elections years
ipolate far_right_votes year, gen(farright_votes_ipol) epolate by(nuts_2) // ipolate votes to fill in non-elections years
ipolate validvotes year, gen(validvotes_ipol) epolate by(nuts_2) // ipolate votes to fill in non-elections years
replace radicalright_votes_ipol=0 if radicalright_votes_ipol<0 // set negative votes equal to zero	
replace extright_cat1_votes_ipol=0 if extright_cat1_votes_ipol<0 // set negative votes equal to zero	
replace farright_votes_ipol=0 if farright_votes_ipol<0	// set negative votes equal to zero
replace validvotes_ipol=1 if validvotes_ipol<0 // set negative votes equal to zero

*** sum European votes by year
sort year
by year: egen radicalright_voteseu=sum(radicalright_votes_ipol)
by year: egen extrightcat1_voteseu=sum(extright_cat1_votes_ipol)
by year: egen farright_voteseu=sum(farright_votes_ipol)
by year: egen validvotes_eu=sum(validvotes_ipol)
gen radicalright_eu=radicalright_voteseu/validvotes_eu
gen farright_eu=farright_voteseu/validvotes_eu
gen extrightcat1_eu=extrightcat1_voteseu/validvotes_eu

**** Label variables
label variable radicalright_eu "European PRR vote share"
label variable farright_eu "European FR vote share"
label variable extrightcat1_eu "European ER vote share"

tsline farright_eu radicalright_eu  extrightcat1_eu if year>=1999&year<2015, graphregion(color(white)) lpattern(solid longdash dash_dot)
cd Graphs
graph save Figure2.gph, replace
graph export Figure2.pdf, replace
cd ..

******* Figure 3
** generate ISO abbrieviations
decode country, generate(countryname)
sort countryname year
encode countryname, gen(country2)
replace country=country2
gen countryname2=upper(countryname)
gen str countrylabel=substr(countryname2,1,3)
replace countrylabel="GBR" if country2==28
replace countrylabel="AUT" if countryname=="Austria"
replace countrylabel="BEL" if countryname=="Belgium"
replace countrylabel="BGR" if countryname=="Bulgaria"
replace countrylabel="HRV" if countryname=="Croatia"
replace countrylabel="DNK" if countryname=="Denmark"
replace countrylabel="DEU" if countryname=="Germany"
replace countrylabel="GRC" if countryname=="Greece"
replace countrylabel="IRL" if countryname=="Ireland"
replace countrylabel="LVA" if countryname=="Latvia"
replace countrylabel="LTU" if countryname=="Lithuania"
replace countrylabel="NLD" if countryname=="Netherlands"
replace countrylabel="PRT" if countryname=="Portugal"
replace countrylabel="ROU" if countryname=="Romania"
replace countrylabel="SVK" if countryname=="Slovakia"
replace countrylabel="SVN" if countryname=="Slovenia"
replace countrylabel="CHE" if countryname=="Switzerland"
replace countrylabel="GBR" if countryname=="U.K."
gen countrylabel2=upper(countrylabel)
*** Bar graph
graph bar ER PRR FR , over(countrylabel2,sort(FR) descending) graphregion(color(white))  xsize(10)
cd Graphs
graph save Figure3.gph, replace
graph export Figure3.pdf, replace
cd ..





***** Figure 4
*** See file FigureA3.do which includes code to produce Figure 4 plus plus code to produce effects on ER vote (where interaction is insignificant)

